﻿using SuporeSliplampApp.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;

namespace SuporeSliplampApp.Views
{
    /// <summary>
    /// DateSettingView.xaml 的交互逻辑
    /// </summary>
    public partial class DateSettingView : Window
    {
        public DateSettingView()
        {
            InitializeComponent();
            if (Common.DateIndex == 0)
            {
                DateComboBox.SelectedIndex = 0;
            }
            if (Common.DateIndex == 1)
            {
                DateComboBox.SelectedIndex = 1;
            }
            if (Common.DateIndex == 2)
            {
                DateComboBox.SelectedIndex = 2;
            }

        }

        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void SaveBtn_Click2(object sender, RoutedEventArgs e)
        {
            try
            {
                Common.DateIndex = DateComboBox.SelectedIndex;
                var settings = new { DateCode = DateComboBox.SelectedIndex };
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(settings, Newtonsoft.Json.Formatting.Indented);
                File.WriteAllText("DateSettings.json", json);

                this.Close();
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}
